/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.leetCode._1_Array_Linked_List;

import com.leetCode.structure.ListNode;

import static com.leetCode.structure.ListNode.str;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/5/10
 */
//easy
public class _01_206_ReverseLinkedList {

    public static ListNode reverseList(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode cur = head;
        ListNode pre = null;
        ListNode temp;
        while (cur != null) {
            temp = cur.next;
            cur.next = pre;
            pre = cur;
            cur = temp;
        }
        return pre;
    }

    public static void main(String[] args) {
        ListNode head = ListNode.build(new int[]{1, 2, 3, 4, 5});
        System.out.println(str(head));
        System.out.println(str(reverseList(head)));
    }
}
